window.ROOT = "";
(function() {
	
	//初始化增删改操作权限
	/*var isAccess=$("#userRoleInfo").text()=="巡检大队"?true:false;
	if(!isAccess){
		$("#inspectAddBtn").parent().empty();	
	}*/
	//初始化分页数据
	var serverData = {};
	var serverTable;
	jQuery(document).ready(function() {
	serverTable = jQuery('#dataTable').DataTable({
			"serverSide" : true,
			"ordering" : false,
			"ajax" : {
				"dataType" : "json",
				"type" : "get",
				"cache" : false,
				"url" : window.rootPath
						+ '/ui/bussinessInspection/page',
				"data" : function(d) {
					return $.extend({}, d,
							serverData);
				}
			},
			columns : [
					{
						data : null,
						defaultContent : ""
					},
					{
						data : 'businesssellerBaseInfo.shopName'
					},
					{
						data : 'businesssellerBaseInfo.shopAdress'
					},
				
					{
						data : 'businesssellerBaseInfo.managementRange'
					},
					
					{
						data : 'businesssellerBaseInfo.managementPerson.name'
					},
					{
						data : 'inspectCondition'
					},
					
					{
						data : 'user.name'
					},
					{
						data : 'user.contactType'
					},

					{
						data : 'inspectDate',
						render: function (data, type, full, meta) {
	                        if (data)
	                            return moment(data).format('YYYY-MM-DD HH:mm');
	                        else
	                            return '';
	                    }
					},
					{
						data : 'remark'
					},
					/*{
						data : null,
						defaultContent : "",
						render : function(data,type, full,meta) {
							var operate="";
							if(isAccess)
								operate= '<button type="button" class="btn btn-sm btn-info editBtn" title="编辑"><i class="fa fa-pencil"></i></button>'
									+ '<button type="button" class="btn btn-sm btn-info delBtn" title="删除"><i class="fa fa-remove"></i></button>';
							
							return operate;

						}
					}*/ ],
				"drawCallback" : function(oSettings) {
				var k = 0;
				var total = oSettings.aiDisplay.length+ oSettings._iDisplayStart;

				for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
					$('td:eq(0)',oSettings.aoData[oSettings.aiDisplay[k]].nTr).text(i + 1);
					k++;
				}

		/*		serverTable.off('click', 'tr');
				serverTable.on('click','tr',function(event) {
					event = event|| window.event;
					var target = event.target|| event.scrElement;
					var data = serverTable.row(this).data();

					if (target.className.indexOf('fa-remove') != -1|| target.className.indexOf('delBtn') != -1) {

						deleteInspection(data);
					}

					if (target.className.indexOf('fa-pencil') != -1|| target.className.indexOf('editBtn') != -1) {

						editInspection(data);
					}

					return;
				});*/
			}
		});
	
	//删除该条巡检,使用的是restful风格的DELETE提交方式
	/*function deleteInspection(data){
		if(confirm('确定删除该条巡检记录?')){
			$.ajax({
				url:window.rootPath+'/ui/bussinessInspection/delete/'+data.id,
				dataType:'json',
				type:'post',
				data:'_method=DELETE',
				success:function(result){
					//返回成功
					if(result.code==1){
						window.location=window.rootPath+'/ui/bussinessInspection';
					}
				}
			});
		}
	};*/

	//RESTFUL风格的GET方式去修改页面
	/*function editInspection(data){
		if(confirm('确定修改该条巡检记录?')){
			//修改页面
			window.location=window.rootPath+'/ui/bussinessInspection/saveOrUpdate/'+data.id;
		}
	};*/
	
	//条件检索
	$(".searchBtn").click(function(){
		serverData.key = jQuery("#inspectSearch").val();
		serverTable.draw();
	});
	//撤销查询
    jQuery('.resetBtn').on('click',function(){
        jQuery('#inspectSearch').val('');
        serverData.key='';
        serverTable.draw();
    });
	//添加数据
	/*$("#inspectAddBtn").click(function(){
		//添加页面,使用get方式不带Id
		window.location=window.rootPath+"/ui/bussinessInspection/saveOrUpdate";
	});*/

});})();